package cn.tedu.circle.admin.content.dao.persist.repository.impl;

import cn.tedu.circle.admin.content.dao.persist.mapper.DynamicsMapper;
import cn.tedu.circle.admin.content.dao.persist.repository.IDynamicsRepository;
import cn.tedu.circle.admin.content.pojo.entity.Dynamics;
import cn.tedu.circle.admin.content.pojo.vo.DynamicsListItemVO;
import cn.tedu.circle.admin.content.pojo.vo.DynamicsStandardVO;
import cn.tedu.circle.common.pojo.vo.PageData;
import cn.tedu.circle.common.util.PageInfoToPageDataConverter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
@Slf4j
@Repository
public class DynamicsRepositoryImpl implements IDynamicsRepository {

    @Autowired
    DynamicsMapper dynamicsMapper;
    @Override
    public PageData<DynamicsListItemVO> list(Integer pageNum,Integer pageSize) {
        log.debug("开始执行【查询文章列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<DynamicsListItemVO> list = dynamicsMapper.list();
        PageInfo<DynamicsListItemVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    @Override
    public DynamicsStandardVO getStandardById(Long id) {
        return dynamicsMapper.getStandardById(id);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据ID删除文章】的数据访问，参数：{}", id);
        return dynamicsMapper.deleteById(id);
    }

    @Override
    public int updateById(Dynamics dynamics) {
        return dynamicsMapper.updateById(dynamics);
    }
}
